package com.dabai.iot.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 比较器枚举
 *
 * @author kev1n
 */
@Getter
@AllArgsConstructor
public enum ComparatorEnum {
    GT("1", "大于"),
    GE("2", "大于等于"),
    LT("3", "小于"),
    LE("4", "小于等于"),
    EQUAL("5", "等于"),
    NOT_EQUAL("6", "不等于"),
    CONTAINS("7", "包含"),
    NOT_CONTAINS("8", "不包含");

    private final String value;
    private final String desc;

    /**
     * 根据 value 获取对应的枚举
     */
    public static ComparatorEnum fromValue(String value) {
        for (ComparatorEnum comparator : values()) {
            if (Objects.equals(comparator.value, value)) {
                return comparator;
            }
        }
        throw new IllegalArgumentException("Invalid comparator value: " + value);
    }
}
